package 补充.多线程;
class Ticket implements Runnable{
    private int ticket=5;
    @Override
    public void run() {
        while(true){
            if(ticket>0){
                try {
                    Thread.sleep(100);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"卖出第"+ticket+"张票，还剩"+--ticket+"张票");
            }
        }
    }
}
public class 线程同步安全 {

    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        Thread thread = new Thread(ticket,"窗口一");
        Thread thread1 = new Thread(ticket,"窗口二");
        Thread thread2 = new Thread(ticket,"窗口三");
        thread.start();
        thread1.start();
        thread2.start();
    }
}
